<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<head th:include="include :: header"></head>
	<th:block th:include="include :: bootstrap-fileinput-css" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-control-add">
		<input name="wgtUrl" type="hidden" id="wgtUrl"/>
		<input name="apkUrl" type="hidden" id="apkUrl"/>
		<input name="ipaUrl" type="hidden" id="ipaUrl"/>
		<div class="form-group">
			<label class="col-sm-3 control-label"><span style="color:red;">*</span>版本名称：</label>
			<div class="col-sm-8">
				<input name="updateTitle" class="form-control" type="text" autocomplete="off" required>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label"><span style="color:red;">*</span>版本信息：</label>
			<div class="col-sm-8">
				<textarea name="updateContent" class="form-control" autocomplete="off" required rows="6"></textarea>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label"><span style="color:red;">*</span>上传安装包：</label>
			<div class="col-sm-8">
				<input id="apkUpload" type="file" multiple name="apkUpload"  class="form-control">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-3 control-label"><span style="color:red;">*</span>版本号：</label>
			<div class="col-sm-8">
				<input name="versionNumber" class="form-control" type="text" autocomplete="off" required>
			</div>
		</div>
	</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
    var prefix = ctx + "business/versionControl";
    $("#form-control-add").validate({
        focusCleanup: true
    });

    $(document).ready(function () {
        $("#apkUpload").fileinput({
            'theme': 'explorer-fas',
            'uploadUrl': prefix + "/savefy",
            allowedFileExtensions: ['wgt','apk','ipa'],//接收的文件后缀
            initialCaption: "请上传安装包",//文本框初始话value
            overwriteInitial: false,
            initialPreviewAsData: true,
            slugCallback : function(filename) {
                return filename.replace('(', '_').replace(']', '_');
            }
        });
        $("#apkUpload").on("fileuploaded", function(event, data, previewId, index) {//上传成功的回调函数
            var image = data.response.msg;
			var packageSuffix = image.substring(image.length-3);
			if (packageSuffix == 'wgt'){
				$("#wgtUrl").val(image);
			}else if (packageSuffix == 'apk'){
				$("#apkUrl").val(image);
			}else if (packageSuffix == 'ipa'){
				$("#ipaUrl").val(image);
			}
        });
    });


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-control-add').serialize());
        }
    }
</script>
</body>
</html>